<template>
  <a-card :bordered="false">
    <a-tabs v-model="activeKey" @change="handleChangeTab">
      <a-tab-pane key="notGenerated" tab="未生成">
        <!-- 查询区域 -->
        <div
          class="table-page-search-wrapper"
          style="display: flex; align-items: center; padding-top: 10px; padding-bottom: 24px; gap: 16px"
        >
          <a-form layout="inline" style="width: 350px">
            <a-form-item label="包装车间">
              <j-search-select-tag
                type="list"
                v-model="packshopCode"
                :dictOptions="dictOptions"
                @change="loadNotGeneratedData"
              />
            </a-form-item>
          </a-form>
          <a-button @click="addPackagePick" type="primary" icon="plus" style="margin-top: -3px">添加</a-button>
        </div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
          <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
          >项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
          <span style="float: right">
            <a-popover title="自定义列" trigger="click" placement="leftBottom">
              <template slot="content">
                <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                  <a-row style="width: 400px">
                    <template v-for="(item, index) in defColumns">
                      <template v-if="item.key !== 'rowIndex' && item.dataIndex !== 'action'">
                        <a-col :span="12"
                          ><a-checkbox :value="item.dataIndex"
                            ><j-ellipsis :value="item.title" :length="10"></j-ellipsis></a-checkbox
                        ></a-col>
                      </template>
                    </template>
                  </a-row>
                </a-checkbox-group>
              </template>
              <a><a-icon type="setting" />设置</a>
            </a-popover>
          </span>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap"
            :scroll="{ x: true }"
            :columns="planColumns"
            :dataSource="waitedTable.dataSource"
            :pagination="{
              ...waitedTable.ipagination,
              onChange: handleWaitedPageChange, // 监听页码变化
              onShowSizeChange: handleWaitedPageSizeChange, // 监听每页数量变化
            }"
            :loading="waitedTable.loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
          >
          </a-table>
        </div>
      </a-tab-pane>
      <a-tab-pane key="tempSave" tab="暂存中">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="loadNotGeneratedData">
            <a-row :gutter="24">
              <a-col :span="24" style="margin-top: 10px">
                <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                  <a-button @click="newPackagePick" type="primary" icon="plus">新增</a-button>
                </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
          <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
          >项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
          <span style="float: right">
            <a-popover title="自定义列" trigger="click" placement="leftBottom">
              <template slot="content">
                <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                  <a-row style="width: 400px">
                    <template v-for="(item, index) in defColumns">
                      <template v-if="item.key !== 'rowIndex' && item.dataIndex !== 'action'">
                        <a-col :span="12"
                          ><a-checkbox :value="item.dataIndex"
                            ><j-ellipsis :value="item.title" :length="10"></j-ellipsis></a-checkbox
                        ></a-col>
                      </template>
                    </template>
                  </a-row>
                </a-checkbox-group>
              </template>
              <a><a-icon type="setting" />设置</a>
            </a-popover>
          </span>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="tempSaveTable"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="tempSaveTable.dataSource"
            :pagination="{
              ...tempSaveTable.ipagination,
              onChange: handleTempSavePageChange, // 监听页码变化
              onShowSizeChange: handleTempSavePageSizeChange, // 监听每页数量变化
            }"
            :loading="tempSaveTable.loading"
            :rowSelection="{
              selectedRowKeys: tempSaveTable.selectedRowKeys,
              onChange: onPackagePickSelectChangeTempSave,
              type: 'radio',
            }"
          >
            <span slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical" />
              <a @click="handleApproval(record)">提交申请</a>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                      <a>删除</a>
                    </a-popconfirm>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </div>
      </a-tab-pane>
      <a-tab-pane key="approved" tab="已审批">
        <div
          class="table-page-search-wrapper"
          style="display: flex; align-items: center; padding-top: 10px; padding-bottom: 24px; gap: 16px"
        >
          <a-form layout="inline" style="width: 350px">
            <a-form-item label="包装车间" prop="packshopCode">
              <j-search-select-tag
                type="list"
                v-model="queryParamApproved.packshopCode"
                :dictOptions="dictOptions"
                placeholder="请选择包装车间"
              />
            </a-form-item>
          </a-form>
          <a-form-item label="制单日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <j-date
              placeholder="请选择开始日期"
              class="query-group-cust"
              v-model="queryParamApproved.createTime_begin"
            ></j-date>
            <span class="query-group-split-cust"></span>
            <j-date
              placeholder="请选择结束日期"
              class="query-group-cust"
              v-model="queryParamApproved.createTime_end"
            ></j-date>
          </a-form-item>
          <a-button type="primary" @click="loadApprovedData" icon="search" style="margin-top: -3px">查询</a-button>
        </div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
          <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
          >项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
          <span style="float: right">
            <a-popover title="自定义列" trigger="click" placement="leftBottom">
              <template slot="content">
                <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                  <a-row style="width: 400px">
                    <template v-for="(item, index) in defColumns">
                      <template v-if="item.key !== 'rowIndex' && item.dataIndex !== 'action'">
                        <a-col :span="12"
                          ><a-checkbox :value="item.dataIndex"
                            ><j-ellipsis :value="item.title" :length="10"></j-ellipsis></a-checkbox
                        ></a-col>
                      </template>
                    </template>
                  </a-row>
                </a-checkbox-group>
              </template>
              <a><a-icon type="setting" />设置</a>
            </a-popover>
          </span>
        </div>
        <a-table
          ref="approvedTable"
          size="middle"
          bordered
          rowKey="id"
          class="j-table-force-nowrap"
          :scroll="{ x: true }"
          :columns="columns"
          :dataSource="approvedTable.dataSource"
          :pagination="{
            ...approvedTable.ipagination,
            onChange: handleApprovedPageChange, // 监听页码变化
            onShowSizeChange: handleApprovedPageSizeChange, // 监听每页数量变化
          }"
          :loading="approvedTable.loading"
          :rowSelection="{
            selectedRowKeys: approvedTable.selectedRowKeys,
            onChange: onPackagePickSelectChangeApproved,
            type: 'radio',
          }"
        >
          <span slot="action" slot-scope="text, record">
            <a @click="handleDetail(record)">详情</a>
            <a-divider type="vertical" />
            <a @click="handleApproval(record)">撤回</a>
            <a-divider type="vertical" />
            <a v-if="record.isClose == 1" @click="OpenOrClose(record)">开启</a>
            <a v-if="record.isClose != 1" @click="OpenOrClose(record)">关闭</a>
            <a-divider type="vertical" />
            <a @click="printPreview(record)">单据打印</a>
          </span>
        </a-table>
      </a-tab-pane>
    </a-tabs>
    <tsl-pro-package-pick-bill-modal ref="modalForm" @ok="modalFormOk" />
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import TslProPackagePickBillModal from './modules/TslProPackagePickBillModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import '@/assets/less/TableExpand.less'
import ActApplyBtn from '@views/flowable/components/ActApplyBtn.vue'
import { getAction, postAction, putAction } from '@api/manage'
import ActHistoricDetailBtn from '@views/flowable/components/ActHistoricDetailBtn.vue'
import { deepClone, getDate } from '../../utils'
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
import { JVXETypes } from '@/components/jeecg/JVxeTable'
import store from '@/store'

export default {
  name: 'TslProPackagePickBillList',
  mixins: [JeecgListMixin, JVxeTableModelMixin],
  components: {
    TslProPackagePickBillModal,
    ActApplyBtn,
    ActHistoricDetailBtn,
  },
  data() {
    return {
      refKeys: ['unDetail', 'noMakeDetail', 'tempSaveDetail', 'approvedDetail'],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
        style: 'width: 28%;',
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      productType: 0,
      packshopCode: '',
      orderCode: '',
      description: '包材领料单管理页面',
      serviceName: 'TslProPackagePickBillService',
      activeKey: 'notGenerated',
      notGeneratedList: [],
      planColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '车间计划',
          key: 'workshopPlanCode',
          dataIndex: 'workshopPlanCode',
          type: JVXETypes.normal,
          align: 'center',
          width: 120,
          sorter: (a, b) => a.workshopPlanCode.localeCompare(b.workshopPlanCode, 'en'),
        },
        {
          title: '订单编号',
          key: 'orderCode',
          dataIndex: 'orderCode',
          type: JVXETypes.normal,
          align: 'center',
          width: 120,
          defaultValue: '',
        },
        {
          title: '客户物料编码',
          key: 'customCode',
          dataIndex: 'customCode',
          type: JVXETypes.normal,
          align: 'center',
          width: '140px',
          defaultValue: '',
        },
        {
          title: '物料编码',
          key: 'productCode',
          dataIndex: 'productCode',
          type: JVXETypes.normal,
          align: 'center',
          width: 120,
          defaultValue: '',
        },
        {
          title: '物料名称',
          key: 'productBatchNo',
          dataIndex: 'productBatchNo',
          type: JVXETypes.normal,
          align: 'center',
          width: 300,
          defaultValue: '',
        },
        {
          title: '规格型号',
          key: 'materialSpec',
          dataIndex: 'materialSpec',
          type: JVXETypes.normal,
          align: 'center',
          width: 100,
        },
        {
          title: '配方号',
          key: 'formulaNumber',
          dataIndex: 'formulaNumber',
          align: 'center',
          width: 100,
          disabled: true,
        },
        {
          title: '主计量单位',
          key: 'meUnit_dictText',
          dataIndex: 'meUnit_dictText',
          dictCode: 'ji_unit',
          type: JVXETypes.select,
          align: 'center',
          width: 100,
          disabled: true,
        },
        {
          title: '计划数量',
          key: 'planQuantity',
          dataIndex: 'planQuantity',
          align: 'center',
          width: 120,
        },
        {
          title: '包装车间',
          key: 'packshopCode_dictText',
          dataIndex: 'packshopCode_dictText',
          type: JVXETypes.select,
          align: 'center',
          width: 120,
          disabled: true,
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark',
          align: 'center',
        },
      ],
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'code',
          sorter: (a, b) => a.code.localeCompare(b.code, 'en'),
        },
        {
          title: '入库仓库',
          align: 'center',
          dataIndex: 'wareNo_dictText',
        },
        {
          title: '领料人',
          align: 'center',
          dataIndex: 'pickBy',
        },
        {
          title: '领料日期',
          align: 'center',
          dataIndex: 'pickDate',
          sorter: (a, b) => a.pickDate.localeCompare(b.pickDate, 'en'),
        },
        {
          title: '领料部门',
          align: 'center',
          dataIndex: 'pickOrgCode_dictText',
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '制单部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'createTime',
          sorter: (a, b) => a.createTime.localeCompare(b.createTime, 'en'),
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      waitedTable: {
        selectedRowKeys: [],
        loading: false,
        dataSource: [],
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      approvedTable: {
        selectedRowKeys: [],
        selectionRows: [],
        loading: false,
        dataSource: [],
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      tempSaveTable: {
        selectedRowKeys: [],
        selectionRows: [],
        loading: false,
        dataSource: [],
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      waitedTable: {
        selectedRowKeys: [],
        selectionRows: [],
        loading: false,
        dataSource: [],
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      url: {
        waitGenerateList: 'pro/tslProWorkshopPlan/queryPackageList',
        list: '/pro/tslProPackagePickBill/list',
        approval: '/pro/tslProPackagePickBill/approval',
        close: '/pro/tslProPackagePickBill/close',
        delete: '/pro/tslProPackagePickBill/delete',
        deleteBatch: '/pro/tslProPackagePickBill/deleteBatch',
        exportXlsUrl: '/pro/tslProPackagePickBill/exportXls',
        importExcelUrl: 'pro/tslProPackagePickBill/importExcel',
        TslProPackagePickBillDetail: '/pro/tslProPackagePickBill/queryTslProPackagePickBillInfoByMainId',
        detail: '/pro/tslProPackagePickBill/queryTslProPackagePickBillDetailByMainId',
        packshopList: '/packageorganization/erpPackageOrganization/list',
        outbound: '/wms/outbound/outbound-order/add',
      },
      dictOptions: [],
      queryParamApproved: {
        createTime_begin: null,
        createTime_end: null,
        order: 'create_by desc',
        packshopCode: '',
        status: 999,
      },
      settingColumns: [],
    }
  },
  created() {
    this.queryParamApproved.createTime_begin = getDate('day', -7)
    this.queryParamApproved.createTime_end = getDate('day', 0)
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    // 未生成页：处理页码变化
    handleWaitedPageChange(page, pageSize) {
      this.waitedTable.ipagination.current = page
      this.waitedTable.ipagination.pageSize = pageSize
      this.getNotGeneratedData()
    },
    // 未生成页：处理每页数量变化
    handleWaitedPageSizeChange(page, pageSize) {
      this.waitedTable.ipagination.current = page
      this.waitedTable.ipagination.pageSize = pageSize
      this.getNotGeneratedData()
    },
    // 暂存中页：处理页码变化
    handleTempSavePageChange(page, pageSize) {
      this.tempSaveTable.ipagination.current = page
      this.tempSaveTable.ipagination.pageSize = pageSize
      this.loadTempSaveData()
    },
    // 暂存中页：处理每页数量变化
    handleTempSavePageSizeChange(page, pageSize) {
      this.tempSaveTable.ipagination.current = page
      this.tempSaveTable.ipagination.pageSize = pageSize
      this.loadTempSaveData()
    },
    // 已审批页：处理页码变化
    handleApprovedPageChange(page, pageSize) {
      this.approvedTable.ipagination.current = page
      this.approvedTable.ipagination.pageSize = pageSize
      this.loadApprovedData()
    },
    // 已审批页：处理每页数量变化
    handleApprovedPageSizeChange(page, pageSize) {
      this.approvedTable.ipagination.current = page
      this.approvedTable.ipagination.pageSize = pageSize
      this.loadApprovedData()
    },
    onPackagePickSelectChangeTempSave(selectedRowKeys, selectedRows) {
      this.tempSaveTable.selectedRowKeys = selectedRowKeys
    },
    onPackagePickSelectChangeApproved(selectedRowKeys, selectedRows) {
      this.approvedTable.selectedRowKeys = selectedRowKeys
    },
    addPackagePick() {
      if (!this.selectedRowKeys || this.selectedRowKeys.length == 0) {
        this.$message.error('请至少选择一条车间生产计划！')
        return
      }
      let selectedRows = []
      this.waitedTable.dataSource.forEach((element) => {
        if (this.selectedRowKeys.includes(element.id)) {
          selectedRows.push(element)
        }
      })
      this.$refs.modalForm.add(selectedRows, this.packshopCode)
      this.$refs.modalForm.title = '添加'
      this.$refs.modalForm.disableSubmit = false
    },
    newPackagePick() {
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    },
    loadNotGeneratedData() {
      if (!this.packshopCode) {
        getAction(this.url.packshopList, { pageSize: 999, pageNo: 1 }).then((res) => {
          if (res.success) {
            let detailData = res.result.records || res.result || []
            if (Array.isArray(detailData)) {
              detailData.forEach((item) => {
                this.dictOptions.push({
                  value: item.departCode,
                  text: item.departName,
                })
              })
            }
            if (this.dictOptions.length > 0 || this.dictOptions.length > 0) {
              this.packshopCode = this.dictOptions[0].value
              this.getNotGeneratedData()
            }
          }
        })
      } else {
        this.getNotGeneratedData()
      }
    },
    getNotGeneratedData() {
      this.selectedRowKeys = []
      this.waitedTable.dataSource = []
      this.waitedTable.loading = true
      getAction(this.url.waitGenerateList, {
        packshopCode: this.packshopCode,
        pageNo: this.waitedTable.ipagination.current,
        pageSize: this.waitedTable.ipagination.pageSize,
      })
        .then((res) => {
          if (res.success) {
            this.waitedTable.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.waitedTable.ipagination.total = res.result.total
            } else {
              this.waitedTable.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.waitedTable.loading = false
        })
    },
    loadTempSaveData() {
      this.tempSaveTable.loading = true
      getAction(this.url.list, {
        status: -2,
        pageNo: this.tempSaveTable.ipagination.current,
        pageSize: this.tempSaveTable.ipagination.pageSize,
      })
        .then((res) => {
          if (res.success) {
            this.tempSaveTable.dataSource = (res.result.records || res.result).filter(
              (item) => item.id !== null && item.id !== undefined
            )
            if (res.result.total) {
              this.tempSaveTable.ipagination.total = res.result.total
            } else {
              this.tempSaveTable.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.tempSaveTable.loading = false
        })
    },
    loadApprovedData() {
      this.approvedTable.loading = true
      this.queryParamApproved.pageNo = this.approvedTable.ipagination.current
      this.queryParamApproved.pageSize = this.approvedTable.ipagination.pageSize
      getAction(this.url.list, this.queryParamApproved)
        .then((res) => {
          if (res.success) {
            this.approvedTable.dataSource = (res.result.records || res.result).filter(
              (item) => item.id !== null && item.id !== undefined
            )
            if (res.result.total) {
              this.approvedTable.ipagination.total = res.result.total
            } else {
              this.approvedTable.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.approvedTable.loading = false
        })
    },
    async OpenOrClose(record) {
      record.isClose = record.isClose == 1 ? 0 : 1
      await postAction(this.url.close, record)
      this.loadApprovedData()
    },
    async handleApproval(record) {
      record.status = record.status == 999 ? -2 : 999
      await postAction(this.url.approval, record)
      if (record.status == 999) {
        getAction(this.url.detail, { id: record.id })
          .then(async (res) => {
            if (res.success && res.result) {
              let warehouse = 0
              let detail = []
              const commonOutbound = {
                outboundType: 2,
                documentNumber: record.code,
                issueDate: record.pickDate,
                targetWarehouseCode: record.wareNo,
              }
              for (const item of res.result) {
                if (item.warehouseCode != warehouse) {
                  if (detail.length > 0) {
                    const outbound = {
                      ...commonOutbound,
                      warehouseCode: warehouse,
                      outboundOrderItemList: detail,
                    }
                    const sys = await putAction('/sys/fillRule/executeRuleByCode/pick_outbound_code', {})
                    if (sys.success) {
                      outbound.outboundNumber = 'BC' + sys.result
                      await postAction(this.url.outbound, outbound)
                    }
                  }
                  detail = []
                  warehouse = item.warehouseCode
                }
                const receivedQty = parseFloat(item.receivedQuantity) || 0
                const rate = parseFloat(item.coRate) || 0
                detail.push({
                  customerMaterialCode: item.customCode,
                  materialCode: item.productCode,
                  materialName: item.productBatchNo,
                  specificationModel: item.materialSpec,
                  unit: item.meUnit,
                  quantity: receivedQty,
                  secondaryUnit: item.auUnit || 0,
                  secondaryQuantity: receivedQty * rate,
                  outboundQuantity: 0,
                  materialBatchNumber: item.materialBatchNumber,
                })
              }
              if (detail.length > 0) {
                const outbound = {
                  ...commonOutbound,
                  warehouseCode: warehouse,
                  outboundOrderItemList: detail,
                }
                const sys = await putAction('/sys/fillRule/executeRuleByCode/pick_outbound_code', {})
                if (sys.success) {
                  outbound.outboundNumber = 'BC' + sys.result
                  await postAction(this.url.outbound, outbound)
                }
              }
            }
          })
          .then(() => {
            this.loadTempSaveData()
          })
      } else {
        this.loadApprovedData()
      }
    },
    async loadData() {
      //分别根据单据状态查询结果并将其放在
      this.handleChangeTab()
    },
    handleChangeTab() {
      switch (this.activeKey) {
        case 'notGenerated':
          this.loadNotGeneratedData()
          break
        case 'tempSave':
          this.loadTempSaveData()
          break
        case 'approved':
          this.loadApprovedData()
          console.log('approved')
          break
        default:
          break
      }
    },
    printPreview(record) {
      let token = store.getters.token
      let id = record.id
      window.open(
        `${window._CONFIG['domianURL']}/jmreport/view/1098794424323100672?token=${token}&id=${id}&table=tsl_pro_package_pick_bill&infoTable=tsl_pro_package_pick_bill_detail`,
        '_blank'
      )
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
::v-deep .ant-table-tbody tr {
  height: 36px !important;
}
</style>
